<template>
	<view class="content">
		<view class="top" @click="scan">
			<view class="top_left" >
				<image class="img" src="../../static/small-scan.png" mode="widthFix"></image>
				<view class="">
					请扫描设备二维码
				</view>
			</view>
			<view class="">
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="title">
			请输入您要反馈的问题
		</view>
		<view class="cont">
			<u--textarea v-model="value1" height='150' placeholder="请输入反馈内容" ></u--textarea>
			
		</view>
		<view class="btn">
			<u-button type="primary" text="提交" @click='submit'></u-button>
		</view>
	</view>
</template>

<script>
	let jweixin = require('jweixin-module');
	export default {
		data() {
			return {
				value1: '',
				deviceCode: ''
			}
		},
		methods: {
			scan(){
				this.getTick()
			},
			getTick(){
				var _this = this
				uni.request({
					url: 'http://www.yndzfl.cn/wxsite/index/getWxJsApiTicketconfig',
					method: 'POST',
					header:{
						"Content-Type" : "application/x-www-form-urlencoded"
					},
					data: {
						url: location.href,
					},
					success: (res) => {
						const dataInfo = res.data.data;
						if (res.data.code == 1) {
							 let jsApiParameters  = {
								   debug: false, // 开启调试模式,调用的所有api的返回值会在客户端//alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
								   appId: dataInfo.appid, // 必填，公众号的唯一标识
								   timestamp: dataInfo.result.timestamp, // 必填，生成签名的时间戳
								   nonceStr: dataInfo.result.noncestr, // 必填，生成签名的随机串
								   signature: dataInfo.result.signature,// 必填，签名，见附录1
								   jsApiList: ['scanQRCode','getLocation','openLocation','chooseImage','getLocalImgData'],
							   }
							jweixin.config(jsApiParameters);
							  jweixin.ready(function(){
								jweixin.scanQRCode({
									needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
									scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
									success: function (res) {
										console.log(res)
										let result = _this.urlParse(res.resultStr);
										if( typeof result === 'object' && result.macno != null){
											_this.deviceCode = result.macno
										}else {
											_this.errorBox = true
										}
									},
									error: function (err) {
										alert('出错了');
									}
								});
							  });
							// window.location.reload()
						} else {
							console.log("设置授权失败")
							return false;
						}
					},
					fail() {
						uni.hideLoading()
						console.log(`后端返回失败 `)
						return false;
					}
				});
			},
			  urlParse(url = '') {
				url = url.split('?')[1] ? url.split('?')[1] : url
				let res = {}
				let kv = url.split('&')
				for (let i = 0; i < kv.length; i++) {
				  let qs = kv[i].split('=')
				  res[decodeURIComponent(qs[0])] = decodeURIComponent(qs[1])
				}
				return res
			  },
			submit(){
				if(!this.deviceCode){
					uni.showToast({
						title: '请扫描设备二维码',
						icon: 'none'
					})
					return
				}
				if(!this.value1){
					uni.showToast({
						title: '请填写维修内容',
						icon: 'none'
					})
					return
				}
				var _this = this
				uni.request({
					url: 'http://www.yndzfl.cn/wxsite/Staff/reportRepair',
					method: 'POST',
					header:{
						"Content-Type" : "application/x-www-form-urlencoded"
					},
					data: {
						token: uni.getStorageSync('token'),
						macno: _this.deviceCode,
						type: 1,
						content: _this.value1
					},
					success(res) {
						if(res.data.code == 1){
							uni.showToast({
								title: '反馈成功',
								icon: 'none'
							})
							setTimeout(function(){
								uni.reLaunch({
									url: '/pages/admin/index'
								})
							},1000)
							
						}else{
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}
						
					}
				})
			}
		}
	}
</script>

<style scoped>
.top{
	height: 50px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	background-color: #fff;
	padding: 0 10px;
}
.top_left{
	display: flex;
	justify-content: start;
	align-items: center;
}
.img{
	width: 20px;
	height: 20px;
	margin-right: 10px;
}
.cont{
	margin-top: 1px;
	padding: 15px;
}
.title{
	/* line-height: 30px; */
	padding:10px 15px 0;
	font-size: 15px;
	font-weight: bold;
}
.btn{
	padding: 15px;
}
</style>
